﻿#ifndef CHATROOM_H
#define CHATROOM_H

#include <QWidget>
#include <QCloseEvent>
#include <QMessageBox>
#include <QTcpSocket>
#include <QListWidget>
#include <vector>
#include <memory>

namespace Ui {
class ChatRoom;
}

struct User; // 前置声明
class ChatRoom : public QWidget
{
    Q_OBJECT

public:
    explicit ChatRoom(QWidget *parent = nullptr);
    ~ChatRoom() override;

    // 发送到服务器
    void WriteToServer(const QJsonObject &obj);

    // 处理json逻辑
    void process(const QByteArray &data);

public slots:
    void GetFromName(const QString &fromName);

    void GetSocket(QTcpSocket *socket);

protected:
    void closeEvent(QCloseEvent *event) override;

signals:
    void ExitChat();

private slots:
    void on_pushButton_chat_clicked();

private:
    Ui::ChatRoom *ui;
    QString name;
    QTcpSocket *socket;
    std::vector<std::shared_ptr<User>> users; // 管理所有的在线用户
};

#endif // CHATROOM_H
